<template>
  <div class="energy-system-container">
    <div class="section">
      <h2 class="section-title">成本参数</h2>
      <div class="info-grid">
        <div class="info-card">
          <label class="info-label">折线率</label>
          <div class="info-content">
            <input type="number" v-model="Flexible_demand" class="form-input small">
            <span class="info-value">MWh</span>
          </div>
            <button class="distribution-btn device-submit-btn" @click="submit">
          <span class="btn-text">提交设备参数</span>

            </button>
        </div>
      </div>
    </div>



  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'

const submit = async () => {
  try {
    const payloads = [
      { id: 1, value: parseFloat(Flexible_demand.value) || 0 },

    ];

    for (const item of payloads) {
      await axios.put('http://localhost:8080/xiangying', item);
    }

    ElMessage.success('已成功更新到数据库');
  } catch (error) {
    console.error('提交失败:', error);
    ElMessage.error('提交失败，请检查数据格式或网络连接');
  }
};

onMounted(async () => {

   const response111 = await axios.get('http://localhost:8080/xiangying/1')

    const data111 = response111.data

    Flexible_demand.value = data111.value

})
    const Flexible_demand = ref('')

</script>

<style scoped>
.electricity-container {
  background-color: #f8fafc;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  border-radius: 14px;
  padding: 12px;
  max-width: 1000px;
  margin: 0 auto;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  color: #1e293b;
}
.section {
  background-color: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 28px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}
.title {
  color: #4c1d95;
  text-align: center;
  margin-bottom: 32px;
  font-size: 28px;
  font-weight: 700;
  padding-bottom: 16px;
  border-bottom: 2px solid #7c3aed;
  letter-spacing: 0.5px;
}

.section-title {
  color: #4c1d95;
  margin-bottom: 24px;
  font-size: 24px;
  font-weight: 700;
  padding-bottom: 12px;
  border-bottom: 2px solid #7c3aed;
}

.form-section, .info-section, .price-section {
  background-color: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 28px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.input-group {
  display: flex;
  margin-bottom: 18px;
  gap: 16px;
}

.input-label {
  min-width: 180px;
  font-weight: 500;
  color: #475569;
  padding-top: 10px;
}

.input-controls {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.input-wrapper {
  display: flex;
  align-items: center;
  /* background-color: #f8fafc; */
  border-radius: 8px;
  padding: 2px;
  border: 1px solid #f8fafc;
}

.form-input {
  padding: 10px 16px;
  border: 1px solid #053676;
  border-radius: 6px;
  width: 80px;
  text-align: right;
  font-size: 15px;
  background: transparent;
  color: #1e293b;
}

.form-input.small {
  width: 100px;

}

.form-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.unit {
  margin: 0 8px;
  color: #64748b;
  font-size: 10px;
  font-weight: 500;
}

.distribution-btn {
  background-color: #7c3aed;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  height: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.distribution-btn:hover {
  background-color: #6d28d9;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.btn-text {
  font-size: 14px;
  line-height: 1.2;
}

.file-name {
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-style: italic;
  margin-top: 2px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.info-card {
  background-color: #f8fafc;
  padding: 18px;
  border-radius: 10px;
  border-left: 4px solid #7c3aed;
  transition: transform 0.2s, box-shadow 0.2s;
}

.info-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.info-label {
  display: block;
  font-weight: 500;
  color: #475569;
  margin-bottom: 10px;
  font-size: 15px;
}

.info-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.info-value {
  font-weight: 600;
  color: #4c1d95;
  font-size: 15px;
  white-space: nowrap;
}

.price-input-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.price-label {
  font-weight: 500;
  color: #475569;
  min-width: 180px;
}

.price-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

@media (max-width: 768px) {
  .electricity-container {
    padding: 24px;
    border-radius: 0;
  }

  .input-group {
    flex-direction: column;
    gap: 8px;
  }

  .input-label {
    min-width: auto;
    padding-top: 0;
    margin-bottom: 6px;
  }

  .input-controls {
    width: 100%;
  }

  .form-input {
    width: 100%;

  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .price-input-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}
</style>
